package com.xinke.juc.case01;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Author：xinke
 * @Date：2025/9/30
 * @Desc:
 */
@Slf4j
public class CreateTread03_futureTask {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 创建任务对象
        FutureTask<Integer> task03 = new FutureTask<>(() -> {
            log.info("FutureTask创建线程");
            return 100;
        });
        // 参数1 是任务对象; 参数2 是线程名字，推荐
        Thread t3 = new Thread(task03, "t3");
        t3.start();
        // 主线程阻塞，同步等待 task 执行完毕的结果
        Integer result = task03.get();
        log.info("结果是：{}", result);
    }
}
